<template>
	<div style="display: flex; justify-content: space-between;">
		<h3 style="width: 30%;"></h3>
		<h3 align="center">管理员 -【 学生管理 】</h3>
		<h4 style="width: 30%;">
			<button @click="go2Add()">添加学生</button>
		</h4>
	</div>
	<hr >
	<div>
		<table style="width: 90%;line-height: 36px;">
			<tr>
				<td>ID</td>
				<td>姓名</td>
				<td>手机号</td>
				<td>班级ID</td>
				<td>班级名称</td>
				<td>头像</td>
				<td>修改</td>
				<td>删除</td>
			</tr>
			<tr v-for="s in stus">
				<td>{{s.uid}}</td>
				<td>{{s.uname}}</td>
				<td>{{s.phone}}</td>
				<td>{{s.clz.clzno}}</td>
				<td>{{s.clz.clzname}}</td>
				<td>
					<img v-bind:src="`${$ip}/api/public/showimg/${s.pic}`"
					style="width: 5vw;height: 5vw">
				</td>
				<td><button @click="go2Update(s.uid)">upd</button></td>
				<td><button @click="doDel(s.uid)">del</button></td>
			</tr>
		</table>
		<h4>
			<button @click="plus(-1)">上一页</button>
			<span>{{paging.cur}}/{{paging.total}}</span>
			<button @click="plus(1)">下一页</button>
		</h4>
	</div>
</template>

<script setup>
	import axios from 'axios';
</script>
<script>
	export default{
		data(){
			return{
				stus :[],
				stu :{},
				//       【行数】   【页】    【总页数】
				paging :{line : 6,cur : 1,total : 0},
			}
		},
		methods:{
			plus(num){
			this.paging.cur += (num);
			//首页判断
			if (this.paging.cur < 1){this.paging.cur = 1;}
			//尾页判断
			if (this.paging.cur > this.paging.total){
				this.paging.cur = this.paging.total;
			}
			console.log("进行上下页");
			console.log(this.paging);
			this.findPage();
			},
			doDel(uid){
				console.log("学生删除");
				
				this.$get("/api/adm/stu/del?uid="+uid
				).then((resp)=>{
					console.log(resp.data.data);
					this.stus = resp.data.data;
					this.$store.state.erropen = true;
					this.$store.state.errmsg = "删除成功";
				})
			},
			findPage(){
				console.log("学生分页");
				console.log(this.paging);
				let fd = new FormData();
				fd.append("pagenum",this.paging.cur);
				fd.append("lines",6);
				this.$postf("/api/adm/stu/findPage",fd
				).then((resp)=>{
					console.log(resp.data.data);
					let total = resp.data.data.total;
					this.paging.total = Math.ceil(total/6);
					this.stus = resp.data.data.students;
				})
			},
			go2Update(uid){
				console.log("去学生添加")
				this.$router.push({
					path:'/adm/stuAdd',
					query:{id:uid}
				});
			},
			go2Add(){
				console.log("去学生添加")
				this.$router.push({
					path:'/adm/stuAdd',
					query:{id:0}
				});
			},
			findAll(){
				console.log("学生准备显示");
				
				this.$get("/api/adm/stu/findAll"
				).then((resp)=>{
					console.log(resp.data.data);
					this.stus = resp.data.data;
				})
			},
		},
		mounted() {
			console.log("初始化加载数据....");
			this.findPage();
		},
	}
</script>

<style>
</style>
